package com.ds.lens.data.controller;

import com.ds.lens.data.service.LensScheduleDowntimeService;
import com.ds.lens.data.vo.BaseOutVO;
import com.ds.lens.data.vo.factory.VOFactory;
import com.ds.lens.data.vo.in.PagedConditionInVO;
import com.ds.lens.data.vo.in.User;
import com.ds.lens.data.vo.in.v2.downtime.LensScheduleDowntimeInVO;
import com.ds.lens.data.vo.in.v2.downtime.LensScheduleDowntimeUpdateInVO;
import com.ds.lens.data.vo.in.v2.downtime.LensScheduleListInVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @author hill
 * @date 2019/11/6 下午2:32
 */
@RestController
@Api(value = "Lens Schedule Downtime controller")
@RequestMapping(produces = {"application/json;charset=UTF-8"})
public class LensScheduleDowntimeController {

    @Autowired
    LensScheduleDowntimeService lensScheduleDowntimeService;

    @ApiOperation(value = "save Schedule Downtime")
    @PostMapping(value = "/lens/downtime/save")
    public BaseOutVO save(@RequestBody @Valid LensScheduleDowntimeInVO inVO,
                                  @RequestAttribute(value = "user") User user) {
        return VOFactory.getSuccessBaseOutVO(lensScheduleDowntimeService.saveDowntime(inVO, user));
    }

    @ApiOperation(value = "delete Schedule Downtime info by id")
    @GetMapping(value = "/lens/downtime/delete")
    public BaseOutVO delete(@RequestParam("id") Long id,
                                        @RequestAttribute(value = "user") User user) {
        return VOFactory.getSuccessBaseOutVO(lensScheduleDowntimeService.deleteDowntimeById(id, user));
    }

    @ApiOperation(value = "Paging for query downtime")
    @PostMapping(value = "/lens/downtime/list")
    public BaseOutVO list(@RequestBody @Valid PagedConditionInVO<LensScheduleListInVO> inVO,
                                     @RequestAttribute(value = "user") User user) {
        return VOFactory.getSuccessBaseOutVO(lensScheduleDowntimeService.listDowntime(inVO, user));
    }

    @ApiOperation(value = "Paging for query monitorList")
    @GetMapping(value = "/lens/downtime/monitorList")
    public BaseOutVO monitorList(@RequestParam("id") Long id,
                                 @RequestAttribute(value = "user") User user) {
        return VOFactory.getSuccessBaseOutVO(lensScheduleDowntimeService.monitorList(id, user));
    }


    @ApiOperation(value = "update downtime")
    @PostMapping(value = "/lens/downtime/update")
    public BaseOutVO update(@RequestBody @Valid LensScheduleDowntimeUpdateInVO inVO,
                                    @RequestAttribute(value = "user") User user) {
        return VOFactory.getSuccessBaseOutVO(lensScheduleDowntimeService.updateDowntime(inVO, user));
    }

    @ApiOperation(value = "get Schedule Downtime info by id")
    @GetMapping(value = "/lens/downtime/get")
    public BaseOutVO getDowntimeById(@RequestParam("id") Long id,
                                        @RequestAttribute(value = "user") User user) {
        return VOFactory.getSuccessBaseOutVO(lensScheduleDowntimeService.getDownTime(id, user));
    }

}
